#include "array_obj.pb.h"
#include <fstream>
#include <iostream>
#include <stdint.h>
#include <vector>
using namespace std;

int main()
{
    MyMessage msg;
    // 添加元素
    msg.add_numbers(1);
    msg.add_numbers(2);
    msg.add_numbers(3);

    // 访问元素
    for (int i = 0; i < msg.numbers_size(); i++)
    {
        std::cout << msg.numbers(i) << std::endl;
    }

    // 或者使用 range-based for 循环 (C++11)
    for (const auto &num : msg.numbers())
    {
        std::cout << num << std::endl;
    }

    // 结构体对象-数组
    Person person;
    person.set_name("Tom");
    person.set_age(20);
    msg.add_people()->CopyFrom(person);
    person.set_name("Jerry");
    person.set_age(22);
    msg.add_people()->CopyFrom(person);
    for (const auto &it: msg.people()){
        std::cout << "name:" << it.name() << ", age:" << it.age() << std::endl;
    }

    return 0;
}
